<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/website/common/base.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${webname }-会员中心</title>
<%@ include file="/website/common/common.jsp"%>
<link href="${webctx }/css/manage.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx}/plugins/plupload2/plupload.full.min.js"></script>
</head>

<body>
<%@ include file="/website/common/top.jsp"%>
<%@ include file="/website/common/head.jsp"%>
<%@ include file="/website/common/menu.jsp"%>

<div class="warp-body">
	<div class="inner clearfix">
    	<div class="left-main">
        	<div class="left-inner">
            	<%@ include file="/website/user/left.jsp"%>
            </div>
        </div>
    	<div class="right-main">
        	<div class="right-inner">
            	<div class="right-title"><span></span>账户管理</div>
                <div class="acc-inner">
                	<ul class="acc-info">
                		<li>
                        	<span>登录账号：</span>
                            ${user.loginname }
                        </li>
                        <li>
                        	<span>昵称：</span>
                            <input name="nickname" type="text" value="${user.nickname }" class="userNameInp">
                        </li>
                		<li>
                        	<span>手机号码：</span>
                            ${user.phone }
                        </li>
                        <li>
                        	<span>邮箱：</span>
                            ${user.email }
                        </li>
                        <li>
                        	<span>会员等级：</span>
                            ${user.gradename }
                        </li>
                        <li><a href="javascript:saveinfo()" class="acc-btn">保 存</a></li>                	
                	</ul>
                    <div class="edit-pic" style="text-align:center">
                    	<span id="uheadimg"><c:if test="${not empty user.photo}"><img src="<%=getRandomFileserver()%>${user.photo}" /></c:if><c:if test="${empty user.photo}"><img src="${webctx }/images/uhead.jpg" /></c:if></span>
                        <a href="javascript:;" id="upheadbtn" style="display:block;margin:8px auto 0 auto;">修改头像</a>
                    </div>
                </div>
                <div class="right-title"><span></span>安全中心</div> 
                <ul class="secure-info">
                	<li>
                    	<div class="sec-title"><b></b>手机绑定</div>
                    	<c:if test="${not empty user.loginphone}"><a href="${ctx }/user/showchangephone">修改</a> 您验证的手机：${user.loginphone.substring(0,3) }*****${user.loginphone.substring(8,user.loginphone.length()) }</c:if>
                    	<c:if test="${empty user.loginphone}"><a href="${ctx }/user/showBindPhone;">绑定</a><em>您未绑定验证手机</em></c:if>
                    </li>
                	<li>
                    	<div class="sec-title"><b></b>登录密码</div>
                    	<a href="${webctx }/user/changePwd.jsp">修改</a> <em>互联网账号登录密码存在盗号风险，建议您定期更改密码以保护账号安全</em>
                    </li>
                </ul>        	
                
            </div>
        </div>
    </div>
</div>

<%@ include file="/website/common/foot.jsp"%>
<link type="text/css" rel="stylesheet" href="${webctx }/css/webeasyui.css">
<script type="text/javascript" src="${ctx}/plugins/oss/upload.js"></script>
<script type="text/javascript" src="${ctx }/util/js/easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx }/util/js/easyui-1.3.3/locale/easyui-lang-zh_CN.js" charset="utf-8"></script>
<script type="text/javascript" src="${ctx }/util/js/webui.js"></script>

</body>
</html>
<script>
var uploader;
$(function(){
	setLeftCur("zhugl");
	
	var plparm={
		runtimes : 'html5,flash,silverlight,html4',
		browse_button :'upheadbtn',
		url : ctx+'/upload/UploadPage@uploadPhoto.page?dir=head&tosave=false',
		flash_swf_url : ctx+'/plugins/plupload2/Moxie2.swf',
		silverlight_xap_url : ctx+'/plugins/plupload2/Moxie.xap',
		multi_selection:false,
		filters: {
			max_file_size : '500kb',
			prevent_duplicates :false, //不允许选取重复文件
		  	mime_types : [ //只允许上传图片文件
		    { title : "图片文件", extensions : "jpg,png,jpeg" }
		  	]
		},init:{
			FilesAdded: function(up, files) {
				uploader.start();
				previewImageOne(files[0],function(imgsrc){
					$("#uheadimg img").attr("src",imgsrc);
				})
			},FileUploaded:function(up,file,responseObject){
				var re=jQuery.parseJSON(responseObject.response);
				$w.httpRequest({
					url:apiroot+"/user/editsave",
					data:{"photo":re.url.replace(re.basepath,"")},
					ok:function(ret){
					}
				})
			},Error:function(up, err){
				if(err.code!="-602"){
					if(err.code=="-600")
						alert("图片大小不能超过500kb");
					else if(err.code=="-601")
						alert("请选择上传jpg或png格式图片");
					else
						alert(err.code+"-"+err.message);
				}
				return false;
			}
		}
	};
	$oss.setUpDir("userhead");
	uploader=$oss.initUpload(plparm);
})
function saveinfo(){
	if($("[name='nickname']").val()==""){
		alert("请输入您的昵称");
		return;
	}
	$w.httpRequest({
		url:apiroot+"/user/editsave",
		data:{"nickname":$("[name='nickname']").val(),"type":"nick"},
		ok:function(ret){
			$web.correctMsg("保存成功");
		}
	})
}
function previewImageOne(file,callback){
	if(!file || !/image\//.test(file.type)) return;
	if(file.type=='image/gif'){
		var fr2 = new mOxie.FileReader();
		fr2.onload = function(){
			callback(fr2.result);
			fr2.destroy();
			fr2 = null;
		}
		fr2.readAsDataURL(file.getSource());
	}else{
		var preloader = new mOxie.Image();
		preloader.onload = function() {
			//preloader.downsize( 300, 300 );
			var imgsrc = preloader.type=='image/jpeg' ? preloader.getAsDataURL('image/jpeg',80) : preloader.getAsDataURL(); //得到图片src,实质为一个base64编码的数据
			callback && callback(imgsrc);
			preloader.destroy();
			preloader = null;
		};
		preloader.load( file.getSource() );
	}
}
</script>